<!--发布计划-->
<template>
    <div>
            <!-- 面包屑导航 -->
            <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>发布计划</el-breadcrumb-item>
            </el-breadcrumb>


            <div style="margin: 10px auto;"></div>

            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane v-for="(item,index) in time" :key="index" :label="item">
                </el-tab-pane>
            </el-tabs>

                    <!--列表-->
        <el-table size="small"  style="width: 100%" :data="workData" highlight-current-row v-loading="loading"  element-loading-text="拼命加载中" >
            
             <el-table-column
                fixed
                width="200"
              prop="id"
              label="序号">
            </el-table-column>
            <el-table-column
                fixed
                width="200"
              prop="startTime"
              label="开始时间">
              <template slot-scope="scope">
                  <div style="color:red;font-size:23px">{{scope.row.startTime}}</div>
              </template>
            </el-table-column>
            <el-table-column
                fixed
                width="200"
              prop="endTime"
              label="结束时间">
              <template slot-scope="scope">
                  <div  style="color:blue;font-size:23px">{{scope.row.endTime}}</div>
              </template>
            </el-table-column>
            <el-table-column
             
              label="操作">
                <template slot-scope="scope">
                    <el-popconfirm
                    @confirm="addSubject(scope.row)"
                    title="确定发布吗？"
                    >
                    <el-button slot="reference"  size="mini"   type="danger" >发 布</el-button>
                </el-popconfirm>
                </template>
            </el-table-column>

        </el-table>
    
    </div>
</template>
<script>
export default {
    data() {
        return {
            activeName:0,
            time:[],
            workData:[],
            loading:false,
            newdate:"",
        }
    },
    created(){
       this.findTime();
    },
    methods:{
         handleClick(tab, event) {
             this.newdate = this.time[tab.index];
            this.findData(this.time[tab.index]) 
        },
        findTime(){  //获取时间
            
            this.$api.get("/subject/findNewTime","",res=>{
                    this.time = res.data.data;
                    this.newdate =this.time[0];
                    this.findData(this.time[0]) 
            })
        },
        findData(time){      //查询数据
            this.loading = true
            setTimeout(()=>{
                    this.loading =false
            },500)
            this.$api.get("/subject/token/findSubjectByTime",{"time":time},res=>{
                 this.workData = res.data.data;
            })
        },
        addSubject(data){ //发布计划
            var a ={"nowdate":this.newdate,"endTime":data.endTime,"startTime":data.startTime,"wid":data.id}
            this.$api.post("/subject/token/addSubjectByCoach",a,res=>{
                   if(res.data.code == 200){
                       this.$message.success("发布成功")
                       this.findData(this.newdate);
                   }
            })
        }
    },
}
</script>
<style scoped>

</style>